package com.zr.controller;

import com.zr.dto.approval.QueryApprovalReqDto;
import com.zr.dto.approval.QueryDetailReqDto;
import com.zr.dto.approval.UpdateFlowReqDto;
import com.zr.service.ApprovalStaffService;
import com.zr.pojo.ReqDto;
import com.zr.pojo.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author dz
 */
@RestController
@RequestMapping("/flow/approval")
public class ApprovalFlowController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ApprovalStaffService approvalStaffService;

    /**
     * 根据审批状态查询员工
     * @param req
     * @return
     */
    @RequestMapping("query")
    @PreAuthorize("hasAuthority('admin')")
    public Result query(@RequestBody ReqDto<QueryApprovalReqDto> req) {

        try {
            return approvalStaffService.query(req);
        } catch (Exception e) {
            logger.info("异常！{}", e);
            return Result.sysFail(e.getMessage());
        }

    }

    /**
     * 根据员工id查询员工明细
     * @return
     */
    @RequestMapping("detail")
    @PreAuthorize("hasAuthority('admin')")
    public Result detail(@RequestBody ReqDto<QueryDetailReqDto> req) {
        try {
            return approvalStaffService.detail(req);
        } catch (Exception e) {
            logger.info("异常！{}", e);
            return Result.sysFail(e.getMessage());
        }

    }

    /**
     * 更新员工审批状态
     * @param req
     * @return
     */
    @RequestMapping("update")
    @PreAuthorize("hasAuthority('admin')")
    public Result update(@RequestBody ReqDto<UpdateFlowReqDto> req) {
        try {
            return approvalStaffService.update(req);
        } catch (Exception e) {
            logger.info("异常！{}", e);
            return Result.sysFail(e.getMessage());
        }
    }
}
